<?php

/*
 * 商品控制器
 * @author sky
 * create_time 2017-03-26
 */


namespace App\Admin\Controllers\Goods;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Intervention\Image\Constraint;
use Intervention\Image\Facades\Image;
use App\Admin\Controllers\Controller;
use App\Admin\Models\Logs;
use App\Admin\Models\UploadImg;
use App\Admin\Models\GoodsUser;

class GoodsUserController extends Controller {


    /*
     * 编辑添加商品
     * @author sky
     * create_time 2017-03-26
     */
    // 添加用户
    public function goodsAdduser(Request $request) {
        if ($request->isMethod('get')) {
            return view('admin.addGoodsUser');
        } elseif ($request->isMethod('post')) {
            $image = $request->file('images');
            $data = UploadImg::upload($image, 'goods');
            $addgoods = array(
            'name' => $request['name'],
            'password' => $request['password'],
            'reg_data' => date('y-m-d h:i:s',time()), 
            'nick' => $request['nick'],
            'img' => $data
        );
            GoodsUser::addGoodsUser($addgoods);
             return view('admin.addGoodsUser');
        }
    }
    // 商品列表
    public function goodsUserList(Request $request) {
        $goods = GoodsUser::goodsUserList();
        $datas['goods'] = $goods;
        return view('admin.goodsUserList', $datas);
    }
     // 删除商品
    public function goodsUserDeleted(Request $request){
        $id=$request->get('id');
        $res = GoodsUser::goodsUserDeleted($id);
        if($res) {
            return "true";
        }else {
            return "false";
        }
        // return view('admin.goodslist');
    }

    // 商品详情
     public function goodsuserdetails(Request $request){
        $id=$request->get('id');
        $details = GoodsUser::goodsuserdetails($id);
        $data['details'] = $details;
        return view('admin.detail',$data);
    }
    // 修改商品
     public function goodsUserUpdates(Request $request){
        if ($request->isMethod('get')) {
            $id=$request->get('id');
            $details = GoodsUser::goodsUserDetail($id);
            $data['details'] = $details;
            return view('admin.goodsuserupdate',$data);
        } elseif ($request->isMethod('post')) {
            $up_id = $request->get('id');
            $addgoods = array(
            'name' => $request->get('name'),
            'password' => $request->get('password'),
            'reg_data' => date('y-m-d h:i:s',time()), 
            'nick' => $request->get('nick')
        );
            GoodsUser::goodsUserUpdatess($up_id,$addgoods);
            return redirect()->route('goods.goodsUserList');

        }
    }
}
